<template>
  <div class="app-wrapper">
    <div class="app-container">
      <h1 class="app-title">视频图片处理工具集</h1>
      <div class="custom-tabs">
        <el-tabs v-model="activeTab" type="card" @tab-change="tabChangeFn">
          <el-tab-pane
            v-for="config in componentsConfigAry"
            :key="config.name"
            :name="config.name"
            :label="config.label"
          />
        </el-tabs>
        <div class="tab-content-wrapper">
          <transition-group name="tab-slide" tag="div" class="tab-content-container">
            <div
              v-for="config in componentsConfigAry"
              :key="config.name"
              v-show="activeTab === config.name"
              class="tab-pane"
            >
              <component :is="componentsMap[config.name]" />
            </div>
          </transition-group>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, shallowRef, defineAsyncComponent } from 'vue';
import componentsConfigAry from './componentsConfig.js';

// 根据配置动态生成组件映射表
const componentsMap = {};
componentsConfigAry.forEach(config => {
  componentsMap[config.name] = defineAsyncComponent(() =>
    import(/* @vite-ignore */ config.componentPath),
  );
});
const activeTab = ref(componentsConfigAry[0]?.name || 'extract-frames');

const tabChangeFn = () => {
  // 可以在这里添加额外的tab切换逻辑
};
</script>

<style>
/* 全局滚动条样式 */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 3px;
}
::-webkit-scrollbar-thumb {
  background: rgba(51, 136, 255, 0.5);
  border-radius: 3px;
  cursor: pointer;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(51, 136, 255, 0.5);
}
html,
body {
  margin: 0;
  padding: 0;
  overflow: hidden;
  font-family: "方正姚体", "Consolas", serif;
}
* {
  font-family: "方正姚体", "Consolas", serif;
}
</style>
<style scoped>
.app-wrapper {
  height: 100vh;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  display: flex;
  align-items: flex-start;
  padding: 20px;
  box-sizing: border-box;
  overflow: hidden;
}
.app-container {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  margin: 0 auto;
}
.app-title {
  margin: 0;
  padding-bottom: 20px;
  color: white;
  text-align: center;
  font-weight: bold;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
  font-size: 2.5rem;
  letter-spacing: 2px;
  line-height: 1;
  animation: fadeInDown 0.8s ease-out;
}
.custom-tabs {
  background-color: white;
  border-radius: 2px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.15);
  padding: 15px;
  animation: fadeInUp 0.8s ease-out 0.2s both;
  overflow: hidden;
  flex: 1;
  display: flex;
  flex-direction: column;
}
.el-tabs__content {
  display: none;
}
/* 标签页样式优化 */
:deep(.el-tabs__header) {
  margin-bottom: 0;
  border-bottom: 0;
}
:deep(.el-tabs--top) {
  padding: 0;
  overflow: hidden;
  --el-tabs-header-height: unset;
}
:deep(.el-tabs__nav-wrap) {
  padding: 10px 15px;
  background: linear-gradient(90deg, #f5f7fa 0%, #c3cfe2 100%);
  border-radius: 2px;
}
:deep(.el-tabs__nav) {
  margin: 0;
  border: 0 !important;
}
:deep(.el-tabs__item) {
  padding: 10px 24px !important;
  border-radius: 2px;
  margin: 0;
  font-weight: 500;
  transition: all 0.3s ease;
  border: 0 !important;
}
:deep(.el-tabs__item.is-active) {
  background: white;
  color: #667eea;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}
:deep(.el-tabs__item:hover) {
  color: #667eea;
}
:deep(.el-tabs__active-bar) {
  background-color: transparent;
}
/* 自定义tab内容容器 */
.tab-content-wrapper {
  position: relative;
  flex: 1;
  padding-top: 15px;
  overflow: hidden;
}
.tab-content-container {
  position: relative;
  width: 100%;
  height: 100%;
}
.tab-pane {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
}
/* 动画效果 */
@keyframes fadeInDown {
  from {
    opacity: 0;
    transform: translateY(-30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
/* 滑动动画 */
.tab-slide-enter-active,
.tab-slide-leave-active {
  transition: all 0.4s ease-out;
}
.tab-slide-enter-from {
  opacity: 0;
  transform: translateX(100%);
}
.tab-slide-leave-to {
  opacity: 0;
  transform: translateX(-100%);
}
.tab-slide-enter-to,
.tab-slide-leave-from {
  opacity: 1;
  transform: translateX(0);
}
:deep(.el-tabs__nav-prev) {
  width: 15px;
  line-height: 35px;
  font-size: 14px;
}
:deep(.el-tabs__nav-next) {
  width: 15px;
  line-height: 35px;
  font-size: 14px;
}
</style>
